﻿Imports System.Data
Imports System.Configuration
Imports System.Linq
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.HtmlControls
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Xml.Linq

Imports System.Text
Imports System.Security.Cryptography
Imports System.Net.NetworkInformation
Imports System.IO
''' <summary>
''' Summary description for clsEncrypt
''' </summary>
Public Class clsEncrypt
    Private bytIV As Byte()
    Private bytKey As Byte()
    Private DES As TripleDESCryptoServiceProvider

    Public Sub New()
        Me.bytKey = Encoding.UTF8.GetBytes("4@7*45#hgKsbdOPde*7^3)g-")
        Me.bytIV = Encoding.UTF8.GetBytes("!#J%Q&)$")
        Me.DES = New TripleDESCryptoServiceProvider()
    End Sub
    Public Function DeCrypt(ByVal strToDeCrypt As String) As String
        If strToDeCrypt Is Nothing OrElse strToDeCrypt.Trim = "" Then Return ""
        Dim buffer As Byte() = Convert.FromBase64String(strToDeCrypt)
        Dim stream As New MemoryStream()
        Dim stream2 As New CryptoStream(stream, Me.DES.CreateDecryptor(Me.bytKey, Me.bytIV), CryptoStreamMode.Write)
        stream2.Write(buffer, 0, buffer.Length)
        stream2.FlushFinalBlock()
        Return Encoding.UTF8.GetString(stream.ToArray())
    End Function
    Public Function EnCrypt(ByVal strToEnCrypt As String) As String
        If strToEnCrypt Is Nothing OrElse strToEnCrypt.Trim = "" Then Return ""
        Dim bytes As Byte() = Encoding.UTF8.GetBytes(strToEnCrypt)
        Dim stream As New MemoryStream()
        Dim stream2 As New CryptoStream(stream, Me.DES.CreateEncryptor(Me.bytKey, Me.bytIV), CryptoStreamMode.Write)
        stream2.Write(bytes, 0, bytes.Length)
        stream2.FlushFinalBlock()
        Return Convert.ToBase64String(stream.ToArray())
    End Function
     
End Class
